<?php

class RegisterView extends RegularView
{
	private $oModel;

	public function __construct(RegisterModel $model = null)
	{
		$this->oModel = $model;	
	}

	protected function title() { return TextManager::i()->text("PAGE_TITLE_REGISTER", false); }
	
	protected function name() { return "register"; }
	
	protected function body()
	{
		$this->registerForm();
	}

	private function registerForm()
	{	
		$errors = array();
		$regAction = false;
		if ($this->oModel instanceof RegisterModel)
		{
			$regAction = true;
			$errors = $this->oModel->errors();
		}
		
	?>
	<form action = "<?php $this->url(array("action" => "register")); ?>" method = "POST">
		<table class = "form_table">
			<tr><td class = "title" colspan = "2"><?php TextManager::i()->text("REGISTER"); ?></td></tr>
			<tr<?php if ($regAction && isset($errors["name"])): ?> class = "error" <?php endif; ?>><td><?php TextManager::i()->text("TITLE_PLAYER_NAME"); ?></td><td><input type = "text" name = "name" value = "<?php if ($regAction) echo htmlspecialchars(Input::request("name")); ?>" /></td></tr>
			<tr<?php if ($regAction && isset($errors["mail"])): ?> class = "error" <?php endif; ?>><td><?php TextManager::i()->text("E-mail"); ?></td><td><input type = "text" name = "mail" value = "<?php if ($regAction) echo htmlspecialchars(Input::request("mail")); ?>" /></td></tr>
			<tr<?php if ($regAction && isset($errors["password"])): ?> class = "error" <?php endif; ?>><td><?php TextManager::i()->text("TITLE_PASSWORD"); ?></td><td><input type = "password" name = "password" value = "<?php if ($regAction) echo htmlspecialchars(Input::request("password")); ?>" /></td></tr>
			<tr<?php if ($regAction && isset($errors["repeat_password"])): ?> class = "error" <?php endif; ?>><td><?php TextManager::i()->text("TITLE_REPEAT_PASSWORD"); ?></td><td><input type = "password" name = "repeat_password" /></td></tr>
			<tr><td colspan = "2" class = "btn"><input type = "submit" value = "<?php TextManager::i()->text("REGISTER"); ?>" /></td></tr>
			<?php foreach ($errors as $error): ?>
				<tr><td class = "error" colspan = "2">*<?php TextManager::i()->text($error); ?></td></tr>
			<?php endforeach; ?>
		</table>
	</form>
	<?php
	}
	
}

?>